
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class CoordinateAxis 
{
    private String absciss_label;
    private String ordinate_label;
    private double reliability = 0.70;
    private ArrayList<Object> statistic_row = new ArrayList<Object>();
    private ArrayList absciss_data = new ArrayList();
    private ArrayList ordinate_data = new ArrayList();
    private Query query = new Query();
    private static ArrayList<ArrayList> statistic_data = new ArrayList<ArrayList>();
    StatisticalData statistic = new StatisticalData();
    CoordinateAxis(String absciss_label, String ordinate_label)
    {
        this.absciss_label = absciss_label;
        this.ordinate_label = ordinate_label;
    }
    public ArrayList getAbscissData()
    {
        return absciss_data;
    }
    public ArrayList getOrdinateDataForFile(Long size, String type, String language,
                                     String compression_level, String compressor)
    {
        if(absciss_label.equals("size"))
        {
            absciss_data = getDifferentItemsFromList(query.getSizesList(type, language));
            ordinate_data = getDataListBySizeForFile(ordinate_label, absciss_data, type, language, 
                                                           compression_level, compressor);
        }
        if(absciss_label.equals("type"))
        {
            absciss_data = getDifferentItemsFromList(query.getTypesList(size, language));
            ordinate_data = getDataListByTypeForFile(ordinate_label, size, absciss_data, language,
                                                           compression_level, compressor);
        }
        if(absciss_label.equals("language"))
        {
            absciss_data = getDifferentItemsFromList(query.getLanguagesList(size, type));
            ordinate_data = getDataListByLanguageForFile(ordinate_label, size, type, absciss_data, 
                                                               compression_level, compressor);
        }
        if(absciss_label.equals("archive_level"))
        {
            absciss_data.add("max");
            absciss_data.add("min");
            absciss_data.add("medium");
            ordinate_data = getDataListByArchiveLevelForFile(ordinate_label, size, type, language, 
                                                                   absciss_data, compressor);
        }
        return ordinate_data;
    }
    public ArrayList getOrdinateDataForCryptoFile(Long size, String type, String language, String compressor,
                                            String crypto_algorithm, String encrypt_mode)
    {
        if(absciss_label.equals("size"))
        {
            absciss_data = getDifferentItemsFromList(query.getSizesList(type, language));
            ordinate_data = getDataListBySizeForCryptoFile(ordinate_label, absciss_data, type, language, 
                                                                 compressor, crypto_algorithm, encrypt_mode);
        }
        if(absciss_label.equals("type"))
        {
            absciss_data = getDifferentItemsFromList(query.getTypesList(size, language));
            ordinate_data = getDataListByTypeForCryptoFile(ordinate_label, size, absciss_data, language, 
                                                                compressor, crypto_algorithm, encrypt_mode);
        }
        if(absciss_label.equals("language"))
        {
            absciss_data = getDifferentItemsFromList(query.getLanguagesList(size, type));
            ordinate_data = getDataListByLanguageForCryptoFile(ordinate_label, size, type, absciss_data, 
                                                                     compressor, crypto_algorithm, encrypt_mode);
        }
        if(absciss_label.equals("encrypt_mode"))
        {
            absciss_data.add("ECB");
            absciss_data.add("CBC");
            absciss_data.add("CFB");
            absciss_data.add("OFB");
            absciss_data.add("PCBC");
            ordinate_data = getDataListByEncryptModeForCryptoFile(ordinate_label, size, type, language, 
                                                                        compressor, crypto_algorithm, absciss_data);
        }
        return ordinate_data;
    }
    private ArrayList getDifferentItemsFromList(List list)
    {
        ArrayList<String> different_item_list = new ArrayList<String>();
        Iterator list_iterator = list.iterator();
        while(list_iterator.hasNext())
        {
           String current_item = list_iterator.next().toString();
           if(different_item_list.contains(current_item) == false)
               different_item_list.add(current_item);            
        }
        return different_item_list;  
    }
    public ArrayList getDataListBySizeForFile(String column_name, List different_sizes_list, 
                                              String type, String language, 
                                              String compression_level, String compressor)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_size_list_iterator = different_sizes_list.iterator();
        while(different_size_list_iterator.hasNext())
        {
            Long size = new Long(Integer.parseInt(different_size_list_iterator.next().toString()));
            List list = query.getDataFromTArchiveFileForColumn(column_name, size, type, language, compression_level, compressor);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);          
            statistic_row.add(compressor);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        
        return different_elements_list;
    }
    public ArrayList getDataListByTypeForFile(String column_name, Long size, List different_types_list, 
                                              String language, String compression_level, String compressor)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_types_list_iterator = different_types_list.iterator();
        while(different_types_list_iterator.hasNext())
        {
            String type = different_types_list_iterator.next().toString();
            List list = query.getDataFromTArchiveFileForColumn(column_name, size, type, language, compression_level, compressor);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(compressor);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }
    public ArrayList getDataListByLanguageForFile(String column_name, Long size, String type,
                                                  List different_languages_list,
                                                  String compression_level, String compressor)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_languages_list_iterator = different_languages_list.iterator();
        while(different_languages_list_iterator.hasNext())
        {
            String language = different_languages_list_iterator.next().toString();
            List list = query.getDataFromTArchiveFileForColumn(column_name, size, type, language, compression_level, compressor);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(compressor);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }
    public ArrayList getDataListByArchiveLevelForFile(String column_name, Long size, String type,
                                                      String language, List different_archive_levels_list,
                                                      String compressor)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_archive_levels_list_iterator = different_archive_levels_list.iterator();
        while(different_archive_levels_list_iterator.hasNext())
        {
            String archive_level = different_archive_levels_list_iterator.next().toString();
            List list = query.getDataFromTArchiveFileForColumn(column_name, size, type, language, archive_level, compressor);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(compressor);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }  
    //------------------------------------------------------------------------------------------------------------------
    public ArrayList getDataListBySizeForCryptoFile(String column_name, List different_sizes_list, 
                                                    String type, String language, String compressor,
                                                    String crypto_algorithm, String encrypt_mode)
    {
        ArrayList different_elements_list = new ArrayList();
        Iterator different_size_list_iterator = different_sizes_list.iterator();
        int number = 1;
        while(different_size_list_iterator.hasNext())
        {
            Long size = new Long(Integer.parseInt(different_size_list_iterator.next().toString()));
            List list = query.getDataFromTArchiveCryptoFileForColumn(column_name, size, type, language, 
                                                           compressor, crypto_algorithm, encrypt_mode);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(crypto_algorithm);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }
     public ArrayList getDataListByTypeForCryptoFile(String column_name, Long size,
                                                     List different_types_list, String language, String compressor,
                                                     String crypto_algorithm, String encrypt_mode)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_types_list_iterator = different_types_list.iterator();
        while(different_types_list_iterator.hasNext())
        {
            String type = different_types_list_iterator.next().toString();
            List list = query.getDataFromTArchiveCryptoFileForColumn(column_name, size, type, language, 
                                                               compressor, crypto_algorithm, encrypt_mode);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(crypto_algorithm);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }
    public ArrayList getDataListByLanguageForCryptoFile(String column_name, Long size, String type,
                                                        List different_languages_list, String compressor,
                                                        String crypto_algorithm, String encrypt_mode)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_languages_list_iterator = different_languages_list.iterator();
        while(different_languages_list_iterator.hasNext())
        {
            String language = different_languages_list_iterator.next().toString();
            List list = query.getDataFromTArchiveCryptoFileForColumn(column_name, size, type, language, 
                                                               compressor, crypto_algorithm, encrypt_mode);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(crypto_algorithm);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }
    public ArrayList getDataListByCompressorForCryptoFile(String column_name, Long size, String type,
                                                          String language, List different_compressors_list,
                                                          String crypto_algorithm, String encrypt_mode)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_compressors_list_iterator = different_compressors_list.iterator();
        while(different_compressors_list_iterator.hasNext())
        {
            String compressor = different_compressors_list_iterator.next().toString();
            List list = query.getDataFromTArchiveCryptoFileForColumn(column_name, size, type, language, 
                                                               compressor, crypto_algorithm, encrypt_mode);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(crypto_algorithm);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }  
    public ArrayList getDataListByEncryptModeForCryptoFile(String column_name, Long size, String type,
                                                           String language, String compressor,
                                                           String crypto_algorithm, List different_encrypt_mode_list)
    {
        ArrayList different_elements_list = new ArrayList();
        int number = 1;
        Iterator different_encrypt_mode_list_iterator = different_encrypt_mode_list.iterator();
        while(different_encrypt_mode_list_iterator.hasNext())
        {
            String encrypt_mode = different_encrypt_mode_list_iterator.next().toString();
            List list = query.getDataFromTArchiveCryptoFileForColumn(column_name, size, type, language, 
                                                               compressor, crypto_algorithm, encrypt_mode);
            double average_value = statistic.getMathematicalExpectation(list);
            statistic_row = statistic.getAllStatisticData(number, list, reliability);
            statistic_row.add(crypto_algorithm);
            statistic_data.add(statistic_row);
            different_elements_list.add(average_value);
            number++;
        }
        return different_elements_list;
    }  
    public static ArrayList<ArrayList> getStatistic()
    {
        return statistic_data;
    }
}
